//
// Created by A on 2022/10/14.
//

#include <stdio.h>
#include <unistd.h>

void fun() {
    while (1) {
        printf("Hello, I'm fun!\n");
        sleep(1);
    }
}

void bar();

void foo();


int main() {
    bar();
    return 0;
}

void foo() {
    int a[5] = {0};
    // 传说中的溢出攻击
    printf("%p\n", fun);
    void *ebp;
    printf("addr of a+4 %x\n", a + 4);
    asm volatile(
            "movl %%ebp,%0"
            :"+m"(ebp)::
            );
    for (int i = 5; i < 25; i++) {
        printf("pos(a[%d]) %x : %x\n", i, a + i, a[i]);
    }
    printf("ret fun addr: &:%p %p\n", &bar, bar);
}

void bar() {
    foo();
}